// 2025/4/29
// 空调遥控

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, p, Mtem = 0; cin >> n >> p;
    vector<int> tempers(n);
    for(auto& tem : tempers)
    {
        cin >> tem;
        Mtem = max(Mtem, tem);
    }
    vector<int> diff(Mtem + 2, 0);
    for(auto& tem : tempers)
    {
        int left = max(tem - p, 1), right = min(tem + p + 1, Mtem + 1);
        ++diff[left];
        --diff[right];
    }
    int ans = 0;
    for(int i = 1; i <= Mtem; i++)
    {
        diff[i] += diff[i - 1];
        ans = max(ans, diff[i]);
    }
    cout << ans << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")